package dukeAll;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

public class AaagmnrsNew {
  public String[] anagrams(String[] phrases){
    HashMap<String, String> map = new HashMap<String, String>();
    for (String str: phrases) {
     char[] chars = str.replaceAll(" ","").toLowerCase().toCharArray();
     Arrays.sort(chars);
     String content = Arrays.toString(chars);
     
     if (!map.containsKey(content))
         map.put(content, str);
    }

    ArrayList<String> al = new ArrayList<String>();
    for (String str: map.values())  
      al.add(str);
      
      
    String[] strings = new String[al.size()];
    al.toArray(strings);
   
    return strings;  
  }
}